
/*
$(function() {
	validateKickout();
    validateRule();
	$('.imgcode').click(function() {
		var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
		$(".imgcode").attr("src", url);
	});
});

$.validator.setDefaults({
    submitHandler: function() {
		login();
    }
});

function login() {
	$.modal.loading($("#btnSubmit").data("loading"));
	var username = $.common.trim($("input[name='username']").val());
    var password = $.common.trim($("input[name='password']").val());
    var validateCode = $("input[name='validateCode']").val();
    var rememberMe = $("input[name='rememberme']").is(':checked');
    $.ajax({
        type: "post",
        url: ctx + "login",
        data: {
            "username": username,
            "password": password,
            "validateCode" : validateCode,
            "rememberMe": rememberMe
        },
        success: function(r) {
            if (r.code == 0) {
                location.href = ctx + 'index';
            } else {
            	$.modal.closeLoading();
            	$('.imgcode').click();
            	$(".code").val("");
            	$.modal.msg(r.msg);
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            }
        },
        messages: {
            username: {
                required: icon + "请输入您的用户名",
            },
            password: {
                required: icon + "请输入您的密码",
            }
        }
    })
}

function validateKickout() {
	if (getParam("kickout") == 1) {
	    layer.alert("<font color='red'>您已在别处登录，请您修改密码或重新登录</font>", {
	        icon: 0,
	        title: "系统提示"
	    },
	    function(index) {
	        //关闭弹窗
	        layer.close(index);
	        if (top != self) {
	            top.location = self.location;
	        } else {
	            var url  =  location.search;
	            if (url) {
	                var oldUrl  = window.location.href;
	                var newUrl  = oldUrl.substring(0,  oldUrl.indexOf('?'));
	                self.location  = newUrl;
	            }
	        }
	    });
	}
}

function getParam(paramName) {
    var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]);
    return null;
}
*/

$(function() {
	$("body").keyup(function(event) {
		if (13 == event.keyCode) {
			ajaxLogin();
		}
	});

	$('.imgcode').click(function() {
		var path = $(this).attr("src");
		var url = ctx + "public/kaptcha/captcha?s=" + Math.random();
		$(".imgcode").attr("src", url);
	});
})

// 保存操作
function ajaxLogin() {
	$("#loginForm").ajaxSubmit({
		url : ctx + "login",
		type : "POST",
		headers : {
			'Content-Type' : 'application/x-www-form-urlencoded' //multipart/form-data;boundary=--xxxxxxx   application/json
		},
		success : function(data) {
			console.log('data = ' + data.message);
			if (data.code == 200) {
				layer.load(1, {
					shade : [ 0.8, '#000' ]
				});
				layer.msg("登陆成功,正在跳转!");
				window.location.href = ctx + data.data;
			} else {
				layer.msg(data.message);
			}
		}
	});
}

// 用户注册
function register() {
	var _phone = $("input[name=loginName]").val();
	var _passwd = $("input[name=password]").val();
	var _code = $("input[name=phoneCode]").val();

	console.log("phone = " + _phone + " , passwd = " + _passwd + " , code = " + _code);
	$.post(ctx + "public/portal/ucenter/register", {
		loginName : _phone,
		password : _passwd,
		phoneCode : _code
	}, function(response) {
		console.log('response = ' + response);
		if (response.code == 200) {
			window.location.href = ctx+ "public/portal/ucenter/login?phone=" + _phone;
		} else {
			layer.alert(response.message == null ? "注册失败.": response.message);
		}
	}, "JSON")
}